//**时间戳转时间*/
export function timestampToTime(timestamp) {
    if (!timestamp) {
        return '';
    }
    var date = new Date(timestamp)
    var Y = date.getFullYear() + '-'
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
    return Y + M + D + h + m + s
}

//**时间戳转日期*/
export function timestampToDate(timestamp) {
    const date = new Date(dateTime);

    const year = date.getFullYear();
    const month = ('0' + (date.getMonth() + 1)).slice(-2); // 月份从0开始，需要加1并且补零
    const day = ('0' + date.getDate()).slice(-2); // 获取日期，并且补零
    const hours = ('0' + date.getHours()).slice(-2); // 获取小时，并且补零
    const minutes = ('0' + date.getMinutes()).slice(-2); // 获取分钟，并且补零
    const seconds = ('0' + date.getSeconds()).slice(-2); // 获取秒钟，并且补零

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

//**时间戳转日期*/
export function timestampToYYYYMM(timestamp) {
    if (!timestamp) {
        return '';
    }
    var date = new Date(timestamp);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    return Y + M;
}

//时间日期转换时间戳
export function dateTurnTimestamp(time) {
    var date = new Date(time);
    var time1 = date.getTime();
    return time1;
}

// 时间戳转时分秒
export function timestampToHms(timestamp) {
    if (!timestamp) return "0时0分";
    return (((Math.floor(timestamp / 3600)).toString()) + "时" + (Math.floor(timestamp % 3600 / 60)).toString() + "分" + ((timestamp % 3600 % 60).toString() < 10 ? "0" + (timestamp % 3600 % 60).toString() : (timestamp % 3600 % 60).toString()) + "秒");
}
